(function () {
	
	$("#avatar").error(function() { 
		$(this).attr("src", "../img/upload.png"); 
		$(this).error=null;
	}); 
	var image;
	$("body").on("change", "#file", function (){
		var $file = $(this);
		var fileObj = $file[0];
		var windowURL = window.URL || window.webkitURL;
		var dataURL;
		var $img = $("#avatar");
		
		if (fileObj && fileObj.files && fileObj.files[0]) {
		    dataURL = windowURL.createObjectURL(fileObj.files[0]);
		} else {
		    dataURL = $file.val();
		    var imgObj = document.getElementById("preview");
		    // 两个坑:
		    // 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
		    // 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
		    imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
		    imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;
		}
		
		//限制上传图片像素大小
		image = new Image();
		image.src = dataURL;
		image.onload = function() { 
			var height = image.height;
			var width = image.width;
			if(width > 30 && height > 30){
				message('请上传30*30像素');
				$file.val(""); 
				return false;
			}
			$img.attr('src', dataURL);
		}
	});
	
	jQuery('#fileclick').on('click', function () {
		if(jQuery('.saveBtn').attr('disabled') && jQuery('.saveBtn').attr('disabled') == 'disabled'){
			return false;
		}else{
			return  $("#file").click();
		}
	});
	
	jQuery("#partLevel").select2().trigger("change");
	
	//添加菜单，弹出弹窗
    jQuery('.addBtn').on('click', function () {
    		jQuery('#id').val('');
    		jQuery('#partParent').val('');
    		jQuery('#partLevel').val('').trigger("change");
    		removeDisabled();
    		
        jQuery('#partName').val('');
        jQuery('#partIdentify').val('');
        jQuery('#partType').val('');

        jQuery('#memo').val('');
    		
        setCheckbox('#userShow',true);
		setCheckbox('#partShow',true);
		setCheckbox('#gridShow',true);
		setCheckbox('#eventShow',true);
    		
    		var file = $("#file") 
    		file.after(file.clone().val("")); 
    		file.remove(); 
    		
    		jQuery("#iconAddress").val('');
    		jQuery("#avatar").attr('src','../img/upload.png');
    		
    		setButtonShow(false,true,false,true); 
    });
    
    jQuery('.addNextBtn').on('click', function () {
		if(serverData2.id == '0'){
			jQuery('#partParent').val('0');
		}else{
			jQuery('#partParent').val(jQuery('#id').val());
		}
		
		jQuery('#id').val('');
		
		var level;
		if(serverData2.id == '0'){
			level = 1;
		}else{
			var objSelect = jQuery("#partLevel option:selected");
			level =  parseInt(objSelect.attr('data-level')) + 1;
		}
		var obj = jQuery("#partLevel option[data-level="+level+"]");
		if(typeof(obj.val()) == 'undefined'){
			jQuery('#partLevel').val('').trigger("change");
			setButtonShow(false,true,false,false);
		}else{
			jQuery('#partLevel').val(obj.val()).trigger("change");
			setButtonShow(false,true,false,true);
		}
	    	
	    	removeDisabled();
	    	
	    	jQuery('#partName').val('');
        jQuery('#partIdentify').val('');
        jQuery('#partType').val('');

        jQuery('#memo').val('');
	         
		var file = $("#file") 
		file.after(file.clone().val("")); 
		file.remove(); 
			
	    	jQuery("#iconAddress").val('');
		jQuery("#avatar").attr('src','../img/upload.png');
	    	
		setCheckbox('#userShow',true);
		setCheckbox('#partShow',true);
		setCheckbox('#gridShow',true);
		setCheckbox('#eventShow',true);
	    	
	});
    
    //table数据显示
    var serverData = {};
    var	serverTable;
    
    //下级层级
    var serverData2 = {};
    serverData2.id = '';
    var	serverTable2;
    
    jQuery(document).ready(function () {
        serverTable=  jQuery('#dataTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "post",
                "cache": false,
                "url": window.rootPath+'/ui/part/getpage',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [{
                		data: null,
                		defaultContent: ""
            		},
    	            {
	            		data: 'iconAddress',
	            		render: function (data, type, full, meta) {
                        if (data && data != ''){
                        		var iconAddress = window.rootPath+'/'+ data;
                        		var operate = '<img src="'+iconAddress+'" width="30px" height="30px"/>';
                            return operate;
                        }else{
                            return '';
                        }
                    }
	            },
                {
            			data: 'partName'
                },
                {
                		data: 'partIdentify'
                },
                {
                		data: 'partType.title'
                },
                {
                		data: 'partLevel.title'
                },
                {
                    data:null,
                    defaultContent: "",
                    render: function(data, type, full, meta){
                        var operate ='<button type="button" class="btn btn-sm btn-info editBtn" title="查看详情"><i class="fa fa-search"></i></button>'
                            +'<button type="button" class="btn btn-sm btn-info delBtn" title="删除"><i class="fa fa-remove"></i></button>'
                            +'<button type="button" class="btn btn-sm btn-info addNode" title="绑定"><i class="fa fa-sign-in"></i></button>';

                        return operate;

                    }
                }],
            "drawCallback": function ( oSettings ) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for ( var i=oSettings._iDisplayStart, iLen=total ; i<iLen ; i++ )
                {
                    $('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[k] ].nTr ).text( i+1 );
                    k++;
                }

                serverTable.off('click','tr');
                serverTable.on( 'click', 'tr', function (event) {
                    event=event||window.event;
                    var target=event.target||event.scrElement;
                    var data = serverTable.row( this ).data();

                    if(target.className.indexOf('fa-remove')!=-1 || target.className.indexOf('delBtn')!=-1){

                        deleteInfo(data);
                    }

                    if(target.className.indexOf('fa-search')!=-1||target.className.indexOf('editBtn')!=-1){

                        editInfo(data);
                    }
                    if(target.className.indexOf('fa-sign-in')!=-1||target.className.indexOf('addNode')!=-1){

                        setNode(data,data.partName);
                    }
                    return;
                } );
            }
        });
        serverTable2 = jQuery('#dataTable2').DataTable({
	        	"serverSide": true,
	        	"ordering": false,
	        	"ajax": {
	        		"dataType": "json",
	        		"type": "post",
	        		"cache": false,
	        		"url": window.rootPath+'/ui/part/getchildrenpage',
	        		"data": function (d) {
	        			return $.extend({}, d, serverData2);
	        		}
	        	},
	        	columns: [{
	        		data: null,
	        		defaultContent: ""
	        	},
            {
            		data: 'iconAddress',
            		render: function (data, type, full, meta) {
                    if (data && data != ''){
                    		var iconAddress = window.rootPath+'/'+ data;
                    		var operate = '<img src="'+iconAddress+'" width="30px" height="30px"/>';
                        return operate;
                    }else{
                        return '';
                    }
                }
            },
	        	{
	        		data: 'partName'
	        	},
	        	{
	        		data: 'partIdentify'
	        	},
	        	{
	        		data: 'partType.title'
	        	},
	        	{
	        		data: 'partLevel.title'
	        	}],
	        	"drawCallback": function ( oSettings ) {
	        		var k = 0;
	        		var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
	        		
	        		for ( var i=oSettings._iDisplayStart, iLen=total ; i<iLen ; i++ )
	        		{
	        			$('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[k] ].nTr ).text( i+1 );
	        			k++;
	        		}
	        		
	        		serverTable2.off('click','tr');
	        		serverTable2.on( 'click', 'tr', function (event) {
	        			event=event||window.event;
	        			var target=event.target||event.scrElement;
	        			var data = serverTable2.row( this ).data();
	        			if(target.className.indexOf('fa-search')!=-1||target.className.indexOf('editBtn')!=-1){
	        				getNode(data.id);
	        			}
	        			return;
	        		} );
	        	}
        });
        
        var deleteInfo=function(data){
            if(!data) return;
            $.springLemonDialog({
                content:'确认模块：'+data.partName+'？',//确认文本
                clickButton:function(sender,modal,index){//按钮事件处理
                    //index:0 确认    1：取消
                    //sender:事件源 如按钮，sender.html()可得到按钮文字如：取消
                    if(index==0){
                        var url=window.rootPath+"/ui/part/delete/"+data.id;
                        jQuery.ajax({
                            url:encodeURI(url),
                            cache:false,
                            type : "post",
                            dataType:"json",
                            success:function(data){
                                serverTable.draw(false);
                                message("删除信息成功!");
                            }
                        });
                    }
                    $(this).closeDialog(modal);
                }

            });

        };
        //编辑信息
        var editInfo=function(data){
            if(!data) return;
            jQuery('#id').val(data.id);
            jQuery('#partParent').val(data.partParent);
            jQuery('#partName').val(data.partName);
            jQuery('#partIdentify').val(data.partIdentify);

            jQuery('#memo').val(data.memo);
            
            var partType = data.partType;
            if(typeof(partType) != 'undefined'){
            		jQuery('#partType').val(data.partType.id);
            }else{
            		jQuery('#partType').val('');
            }
        		var partLevel = data.partLevel;
        		
        		setCheckbox('#userShow',data.userShow);
            setCheckbox('#partShow',data.partShow);
            setCheckbox('#gridShow',data.gridShow);
            setCheckbox('#eventShow',data.eventShow);
        		
            if(typeof(partLevel) != 'undefined'){
            		jQuery('#partLevel').val(partLevel.id).trigger("change");
            		if('' != jQuery('#partLevel').val(partLevel.id)){
            			jQuery('#partIdentify').removeAttr("disabled");
            			var obj = $("#partLevel option:selected");
            			var length = obj.attr('data-length');
            			if(length == 0){
            				jQuery('#partIdentify').val('');
            				jQuery('#partIdentify').removeAttr("datatype");
            			}else{
            				var datatype = '*,*1-'+length;
            				jQuery('#partIdentify').attr('datatype',datatype);
            			}
            		}
            }else{
            		jQuery('#partLevel').val('').trigger("change");
            }
            
			var file = $("#file") 
	    		file.after(file.clone().val("")); 
	    		file.remove(); 
    		
            var iconAddress = data.iconAddress;
            jQuery('#iconAddress').val(iconAddress);
            if(typeof(iconAddress) != 'undefined' && iconAddress != ''){
            		iconAddress = window.rootPath+'/'+ iconAddress;
            }else{
            		iconAddress = '../img/upload.png';
            }
            $("#avatar").attr('src',iconAddress);
            
            addDisabled();
            setButtonShow(false,true,true,false);
        };
        
        //查询
        jQuery('.searchBtn').on('click',function(){
            serverData.key=jQuery('#search').val();
            serverTable.draw();
        })
        
        //撤销查询
        jQuery('.resetBtn').on("click",function()
        {
            jQuery('#search').val('');
            serverData.key ='';
            serverTable.draw();
        });
        
        //查询
        jQuery('.searchBtn2').on('click',function(){
        	serverData2.key=jQuery('#search2').val();
        	serverTable2.draw();
        })
        
        //撤销查询
        jQuery('.resetBtn2').on("click",function(){
	        	jQuery('#search2').val('');
	        	serverData2.key ='';
	        	serverTable2.draw();
    		});
        
        jQuery('.editInfoBtn').on('click',function(){
    			setButtonShow(false,true,false,true);
			removeDisabled();
        });
        
        //新增，编辑保存
        jQuery('.saveBtn').on('click',function(){
            if(jQuery("#modalForm") && !jQuery("#modalForm").Validform({tiptype:3, showAllError:true}).check(false)){
                return;
            };
            $("#right").mLoading("showNoIcon");
            var data={
                    id:jQuery('#id').val(),
                    partParent:jQuery('#partParent').val(),
                    partName:jQuery('#partName').val(),
                    partIdentify:jQuery('#partIdentify').val(),
                    partLevel:jQuery('#partLevel').val(),
                    partType:jQuery('#partType').val(),
                    userShow : jQuery('#userShow').is(":checked"),
                    partShow : jQuery('#partShow').is(":checked"),
                    gridShow : jQuery('#gridShow').is(":checked"),
                    eventShow : jQuery('#eventShow').is(":checked"),
                    iconAddress : jQuery('#iconAddress').val(),
                    memo : jQuery('#memo').val()
                };
            var url=window.rootPath+'/ui/part/savePartWithFile';
	        	$.ajaxFileUpload({
		    		url : url,
		    		secureuri : false,// 是否需要安全协议
		    		fileElementId : ["file"],// 文件上传的Id属性
		    		dataType : 'json',
		    		data : data,
		    		success : function(result, status) {
		    			message(result.msg);
		    			if(result.code == '1' ){
		    				jQuery('.addBtn').click();
	                    refreshNode();
	                    serverTable.draw(false);
                		}
		    			$("#right").mLoading("hide");
		    		}
	        });
        });
        
        //select2 选择事件
        jQuery("#partLevel").on('select2:select',function(){
        		var obj = $("#partLevel option:selected");
        		var partLevelId = obj.val();
        		if(''==partLevelId){
        			jQuery('#partIdentify').val('');
        	        jQuery('#partIdentify').attr('disabled',true);
        		}else{
        			var length = obj.attr('data-length');
        			if(length == 0){
        				jQuery('#partIdentify').val('');
        				jQuery('#partIdentify').attr("disabled",true);
        				jQuery('#partIdentify').removeAttr("datatype");
        			}else{
        				var datatype = '*,*1-'+length;
        				jQuery('#partIdentify').removeAttr("disabled");
        				jQuery('#partIdentify').attr('datatype',datatype);
        			}
        		}
    		});
        
        jQuery('.addBtn').click();
    });

    ////////////////初始化模型的树结构/////////////////////////
    var modalSetting = {
        edit:{
            enable: true,
            showRemoveBtn:setRemoveBtn,
            showRenameBtn:false,
            drag:{
            		isCopy: false,
            		isMove: true,
            		prev: true,
            		next: true,
            		inner: true
            }
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "parentId",
                rootParentId: 0
            }
        },
        view:{
            showLine:true
        },
        check: {
			enable: false,
			chkStyle: "radio",
			radioType: "level"
		},
        callback:{
            beforeRemove: beforeRemove,
            onRemove:onRemove,
            //onCheck:editNewModule,
            beforeDrag:beforeDrag,
            beforeDrop:beforeDrop,
            onClick:getInfo,
            onNodeCreated: zTreeOnNodeCreated
        }

    };
    
    //设置tree图标大小
    function zTreeOnNodeCreated(event, treeId, treeNode) {
    		if(treeNode.type != "folder"){
    			$('#'+treeNode.tId+'_ico').css("background", "url('"+treeNode.icon+"') center center/16px 16px no-repeat");
    		}
    	}
    
    //获取子节点信息列表
    function getInfo(e, treeId, treeNode){
    		var Id=treeNode.id;
	    	serverData2.id = Id;
	    	serverTable2.draw(false);
	    	if('0' == Id) return;
    		getNode(Id);
    }
    
    //菜单树点击编辑节点
    function editNewModule(e, treeId, treeNode){
    		var Id=treeNode.id;
    		if('0' == Id) return;
    		getNode(Id);
    }
    
    function getNode(Id){
        var url=window.rootPath +'/ui/part/getNode'+'?Id='+Id;
        jQuery.ajax({
            url:url,
            cache:false,
            type :"get",
            dataType:"json",
            contentType:'application/json;charset=utf-8',//解决返回数据中的中文乱码问题
            success:function(data){
                jQuery('#id').val(data.node.id);
                jQuery('#partParent').val(data.node.partParent);
                jQuery('#partName').val(data.node.partName);
                jQuery('#partIdentify').val(data.node.partIdentify);
                jQuery('#partType').val(data.node.partType.id);

                jQuery('#memo').val(data.node.memo);
                
                setCheckbox('#userShow',data.node.userShow);
	        		setCheckbox('#partShow',data.node.partShow);
	        		setCheckbox('#gridShow',data.node.gridShow);
	        		setCheckbox('#eventShow',data.node.eventShow);
	    			
            		var partLevel = data.node.partLevel;
                if(typeof(partLevel) != 'undefined'){
                		jQuery('#partLevel').val(partLevel.id).trigger("change");
                		if('' != jQuery('#partLevel').val(partLevel.id)){
                			jQuery('#partIdentify').removeAttr("disabled");
                			var obj = $("#partLevel option:selected");
                			var length = obj.attr('data-length');
                			if(length == 0){
                				jQuery('#partIdentify').val('');
                				jQuery('#partIdentify').removeAttr("datatype");
                			}else{
                				var datatype = '*,*1-'+length;
                				jQuery('#partIdentify').attr('datatype',datatype);
                			}
                		}
                }else{
                		jQuery('#partLevel').val('').trigger("change");
                }

                var file = $("#file") 
		    		file.after(file.clone().val("")); 
		    		file.remove();
	    		
                var iconAddress = data.node.iconAddress;
                jQuery('#iconAddress').val(iconAddress);
                if(typeof(iconAddress) != 'undefined' && iconAddress != ''){
                		iconAddress = window.rootPath+'/'+ iconAddress;
                }else{
                		iconAddress = '../img/upload.png';
                }
                $("#avatar").attr('src',iconAddress);
                
                addDisabled();
                setButtonShow(true,true,true,false);
            }
        });	
    }
    
    //删除按钮的设置
    function setRemoveBtn(treeId, treeNode) {
        //判断为顶级节点则不显示删除按钮
        if(treeNode.level == 0)
            return false;
        else
            return true;

    }
    
  //拖拽前执行  
    var level;
    function beforeDrag(treeId, treeNodes) {
    		if(treeNodes.length > 1){
    			message("一次只能移动一个节点信息!");
    			return false;
    		}
		level = treeNodes[0].level;  
    		return true;  
    }  
     //拖拽释放之后执行  
    function beforeDrop(treeId, treeNodes, targetNode, moveType) {
        if((level == targetNode.level && moveType != 'inner' ) || (level == targetNode.level + 1 && moveType == 'inner' )){
             var d = {id:treeNodes[0].id,targetId:targetNode.id,moveType:moveType};  
             var url=window.rootPath +'/ui/part/move';
             jQuery.ajax({
                 url:encodeURI(url),
                 type :"post",
                 data:JSON.stringify(d),
                 dataType:"json",
                 contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
                 success: function(data){
                	 	if(data.code != '1'){
              	 		message(data.msg);
              	 	}
             	 	refreshNode();
                	 	
                 }
             });  
            //return true;  
        } else{
        		message('只能进行同级排序！');  
        		return false;  
        }  
    }
    
    //初始化 层级树
    var primaryNode=[];
    var url = window.rootPath +'/ui/part/getAllNodes';
    jQuery.ajax({
        url:url,
        cache:false,
        type :"get",
        data:'',
        dataType:"json",
        contentType:'application/json;charset=utf-8',//解决返回数据中的中文乱码问题
        success:function(data){
            primaryNode.push(
                {
                    id: 0,
                    name: "部件层级",
                    open: "true",
                    level:0,
                    icon: "/wcsi/img/defaultPart.png"
                }
            );
            for (var i = 0; i < data.nodes.length; i++) {
                primaryNode.push(data.nodes[i]);
            }
            $.fn.zTree.init($("#partTree"),modalSetting,primaryNode);
        }
    });
    
    /** 
     * 刷新当前节点 
     */  
    function refreshNode() {
    		jQuery.ajax({
            url:url,
            cache:false,
            type :"get",
            data:'',
            dataType:"json",
            contentType:'application/json;charset=utf-8',//解决返回数据中的中文乱码问题
            success:function(data){
            		    primaryNode = [];
                    primaryNode.push(
                        {
                            id: 0,
                            name: "部件层级",
                            open: "true",
                            level:0,
                            icon: "/wcsi/img/defaultPart.png"
                        }
                    );
                    for (var i = 0; i < data.nodes.length; i++) {
                        primaryNode.push(data.nodes[i]);
                    }
                $.fn.zTree.init($("#partTree"),modalSetting,primaryNode);
            }
        });
    	
    }
    
    //////////////////删除节点/////////////////////////////
    function beforeRemove(treeId, treeNode) {
        return confirm("确认删除 " + treeNode.name + "节点 吗？");
    }
    function onRemove(e, treeId, treeNode) {
        //此处treeNode 为当前节点,
        var str ='' ;
        var selectPId=treeNode.getParentNode().id;
        var url=window.rootPath+'/ui/part/deleteNodes';
        str=treeNode.id;
        str = getAllChildrenNodes(treeNode,str);//获得所有id的字符串，方法在myTree.js
        var d = {
                "str":str,
                "selectPId":selectPId
            }
        jQuery.ajax({
            url:encodeURI(url),
            type :"post",
            data:JSON.stringify(d),
            dataType:"json",
            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
            success:function(data){
                serverTable.draw(false);
            }
        });
    }

    ////////////////添加节点///////////////////////////////
    function setNode(data,levelName){
        var treeObj= $.fn.zTree.getZTreeObj("partTree");
        var selectNodes=treeObj.getSelectedNodes(treeObj);
        var selectNode=selectNodes[0];
        var levelName=levelName;
        if(selectNode){
            var parentLevel = selectNode.level;
            var nodeLevel = data.partLevel.extended1;
            if(parentLevel != (nodeLevel - 1)){
            		message("只能绑定相匹配的部件层级信息！");
            		return;
            }
            $.springLemonDialog({
                title:'系统提示',//标题   默认为   系统提示
                content:'是否要绑定'+levelName+'节点？',//确认文本
                bootstrapModalOption:{keyboard: true},
                clickButton:function(sender,modal,index){//按钮事件处理
                    //index:0 确认    1：取消
                    //sender:事件源 如按钮，sender.html()可得到按钮文字如：取消
                    if(index==0){
                        var url=window.rootPath+'/ui/part/saveNode';
                        var d = {
                                "parentId":selectNode.id,
                                "id":data.id
                            };
                        jQuery.ajax({
                            url:encodeURI(url),
                            cache:false,
                            type :"post",
                            data: JSON.stringify(d),
                            dataType:"json",
                            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
                            success:function(data){
                                if(data.code==1){
                                    var newNode={
                                        "id": data.Part.id,
                                        "parentId":selectNode.id,
                                        "name":levelName,
                                        "level":data.Part.partLevel.extended1
                                        //   iconSkin:"diy05"

                                    }
                                    selectNode=treeObj.addNodes(selectNode,newNode);
                                    refreshNode();
                                }else{
                                		message(data.msg);
                                }
                                serverTable.draw(false);
                            }
                        });
                    }
                    $(this).closeDialog(modal);
                }
            });
        }
        else{
            $.springLemonDialog({
                title:'系统提示',//标题   默认为   系统提示
                content:'请选择一个节点',//确认文本
                bootstrapModalOption:{keyboard: true},
                clickButton:function(sender,modal,index){//按钮事件处理
                    //index:0 确认    1：取消
                    //sender:事件源 如按钮，sender.html()可得到按钮文字如：取消
                    $(this).closeDialog(modal);
                }

            });
        }
    }
    
    function addDisabled(){
        jQuery('#partIdentify').attr('disabled',true);
        jQuery('#partLevel').attr('disabled',true);
        
    		jQuery('#partName').attr('disabled',true);
        jQuery('#partType').attr('disabled',true);

        jQuery('#memo').attr('disabled',true);

		jQuery('#userShow').attr('disabled',true);
		jQuery('#partShow').attr('disabled',true);
		jQuery('#gridShow').attr('disabled',true);
		jQuery('#eventShow').attr('disabled',true);
    }
    
    function removeDisabled(){
    	
    		var partParent = jQuery('#partParent').val();
    		
    		jQuery('#partName').removeAttr("disabled");
        jQuery('#partType').removeAttr("disabled");

        jQuery('#memo').removeAttr("disabled");
		
		jQuery('#userShow').removeAttr("disabled");
		jQuery('#partShow').removeAttr("disabled");
		jQuery('#gridShow').removeAttr("disabled");
		jQuery('#eventShow').removeAttr("disabled");
		
		if(partParent == ''){
			jQuery('#partLevel').removeAttr('disabled');
		}else{
			jQuery('#partLevel').attr('disabled',true);
		}
		
		var obj = $("#partLevel option:selected");
		var length = obj.attr('data-length');
		if(typeof(length) == 'undefined' || length == 0){
			jQuery('#partIdentify').val('');
			jQuery('#partIdentify').attr("disabled",true);
			jQuery('#partIdentify').removeAttr("datatype");
		}else{
			var datatype = '*,*1-'+length;
			jQuery('#partIdentify').attr('datatype',datatype);
			if(partParent == '' || jQuery('#id').val() == ''){
				jQuery('#partIdentify').removeAttr('disabled');
			}
		}
    }
    
    function setButtonShow(addNextBtn,addBtn,editInfoBtn,saveBtn){
    		if(addNextBtn){
    			jQuery('.addNextBtn').removeAttr('disabled'); 
    		}else{
    			jQuery('.addNextBtn').attr('disabled',true);
    		}
    		if(addBtn){
    			jQuery('.addBtn').removeAttr('disabled'); 
    		}else{
    			jQuery('.addBtn').attr('disabled',true);
    		}
    		if(editInfoBtn){
    			jQuery('.editInfoBtn').removeAttr('disabled'); 
    		}else{
    			jQuery('.editInfoBtn').attr('disabled',true);
    		}
    		if(saveBtn){
    			jQuery('.saveBtn').removeAttr('disabled'); 
    		}else{
    			jQuery('.saveBtn').attr('disabled',true);
    		}
    }
    
    function setCheckbox(obj,value){
		$(obj).prop("checked", value);
    }

})();